/*
 * eniac-lib.cpp
 *
 *  Created on: 4-apr-2009
 *      Author: fabrizio
 */

#include "eniac-lib.h"

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

EniacLib::EniacLib(SceneMngr *smgr)
{
  Smgr = smgr;

  loadEniacLib(&Parser.vm);
  loadMathLib();

  Data x = Data(Smgr->Device->getCursorControl()->getPosition().X);
  Data y = Data(Smgr->Device->getCursorControl()->getPosition().Y);
  Data event = Data(Smgr->getCursor()->MouseEvent);
  Data button = Data(Smgr->getCursor()->MouseButton);
  Parser.doString("Mouse {x:"+x.toString()+" y:"+y.toString()+
                  " event:"+event.toString()+" button:"+button.toString()+"}");

  Data width = Data((int)Smgr->Device->getVideoDriver()->getScreenSize().Width);
  Data height = Data((int)Smgr->Device->getVideoDriver()->getScreenSize().Height);
  Parser.doString("Screen {width:"+width.toString()+" height:"+height.toString()+"}");

}

EniacLib::~EniacLib()
{

}

Data EniacLib::eniacNODE_GoTo(const Data & args, eniacVm & vm)
{
  int target = args.getData(0).Num().real();
  int eff = args.getData(1).Num().real();
  int time = args.getData(2).Num().real();
  float factor = args.getData(3).Num().real();
  ETRANSITION_TYPE effect = ETT_FADE;

  if(args.getData(1).Str() == "fade") effect = ETT_FADE;
  if(args.getData(1).Str() == "rotate") effect = ETT_ROTATE;
  if(args.getData(1).Str() == "wipe") effect = ETT_WIPE;

  switch(eff)
  {
  	case 0:
  		effect = ETT_FADE;
  		break;
  	case 1:
  		effect = ETT_ROTATE;
  		break;
  	case 2:
  		effect = ETT_WIPE;
  		break;
  	default:
  		break;
  }
  Smgr->gotoNode(target,effect,time,factor);
	return Data(false);
}


